/*
 * Copyright (c) GoKeep by gokeep.org. 2022-2023. All rights reserved
 */
package org.gokeep.application.config;

import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import jakarta.annotation.Resource;
import org.gokeep.common.config.properties.CacheProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


/**
 * 本地缓存配置, 初始化100条数据，总计最大条数为1000000条数据
 */
@Configuration
public class CaffeineConfig {

    @Resource
    private CacheProperties cacheProperties;

    @Bean
    public <T> Cache<String, T> cache() {
        return Caffeine.newBuilder()
                .initialCapacity(cacheProperties.getCaffeine().getInitialCapacity())
                .maximumSize(cacheProperties.getCaffeine().getMaximumSize())
                .build();
    }
}
